package com.uaaone.service;

import com.alibaba.druid.util.StringUtils;
import com.uaaone.entity.CustomUser;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.oauth2.common.exceptions.InvalidGrantException;
import org.springframework.stereotype.Service;

/**
 * @author iszengziqiang@163.com
 * @date 2021-10-25 16:25
 * @Version: 1.0
 * @desc
 */
@Service
public class CustomUserDetailsService {
    public CustomUser loadUserByMobileAndPassword(String mobile, String password) {
        System.out.println("手机号和密码登录：" + mobile + "####" + password);
        if (StringUtils.isEmpty(mobile) || StringUtils.isEmpty(password)) {
            throw new InvalidGrantException("您输入的手机号或密码不正确");
        }
        // 判断成功后返回用户细节
        return new CustomUser("匿名者", mobile, "https://www.google.cn/favicon.ico", AuthorityUtils.commaSeparatedStringToAuthorityList("admin,user,root"));
    }

    public CustomUser loadUserByMobileAndSmscode(String mobile, String smscode) {
        System.out.println("手机号和短信登录：" + mobile + "####" + smscode);
        if (StringUtils.isEmpty(mobile) || StringUtils.isEmpty(smscode)) {
            throw new InvalidGrantException("您输入的手机号或短信验证码不正确");
        }
        // 判断成功后返回用户细节
        return new CustomUser("匿名者", mobile, "https://www.google.cn/favicon.ico", AuthorityUtils.commaSeparatedStringToAuthorityList("admin,user,root"));
    }

}
